package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) throws Exception {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册", "注册");
//        System.out.println(userInfo);

//        Weibo weibo = InputUtil.getInputObject(new Weibo());
//        System.out.println(weibo);

        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://10.172.23.77:23307/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "123456TCP"
        );

        Statement statement = connection.createStatement();


//        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入用户名");
//        String username = "'" + scan.nextLine() + "'";
//        System.out.println("请输入密码");
//        String pwd = "'" + scan.nextLine() + "'";
//        System.out.println("请输入昵称");
//        String nickname= "'" + scan.nextLine() + "'";
//        System.out.println("请输入年龄");
//        int age = Integer.parseInt(scan.nextLine());

        String sql = "insert into userinfo(username, password, nickname, age) " +
                "values ('" + userInfo.getUsername() + "', '" + userInfo.getPassword() + "','" + userInfo.getNickname() + "', " + userInfo.getAge() + ")";


        int num = statement.executeUpdate(sql);
        if (num > 0) {
            System.out.println("插入成功");
        }
        connection.close();

    }
}
